package net.esj.basic.dao.ann.criterion.condition.logic;

import java.util.ArrayList;
import java.util.Collection;

import net.esj.basic.dao.ann.criterion.condition.Condition;

public class AndCondition implements LogicCondition {

	private Collection<Condition> conditions;
	
	public AndCondition(Collection<Condition> conditions) {
		super();
		this.conditions = conditions;
	}
	
	public AndCondition() {
		super();
		this.conditions = new ArrayList<Condition>();
	}

	@Override
	public String toSql() {
		StringBuilder sb = new StringBuilder();
		int i=0;
		for(Condition cond:conditions){
			if(i==0){
				sb.append(cond.toSql());
			}else{
				sb.append(" AND ").append(cond.toSql());
			}
			i++;
		}
		return sb.toString() ;
	}

	@Override
	public void notifyLogic(Condition condition) {
		conditions.add(condition);
	}

}
